package main

import (
	"fmt"
	"html/template"
	"net/http"
	"os"
	"path/filepath"
)

func sayHello(w http.ResponseWriter,r *http.Request)  {
	// ./ 代表项目路径
	t, err := template.ParseFiles("./test.tmpl")

	if err != nil {
		fmt.Printf("parse file failed err := %v",err)
	}
	strings := []string{"张安","潘凤","李翔"}
	err = t.Execute(w,strings)
	if err != nil {
		fmt.Printf("execute file failed err := %v",err)
	}

}

func main() {
	http.HandleFunc("/",sayHello)
	root := filepath.Dir(os.Args[0])
	fmt.Println(root)
	err := http.ListenAndServe(":9000", nil)
	if err != nil {
		fmt.Printf("listen address failed err = %v",err)
	}
}
